package com.imti.controller;




import com.imti.Api.CommonResult;
import com.imti.entity.Account;
import com.imti.service.AccountService;
import com.imti.service.RedisService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * (Account)表控制层
 *
 * @author makejava
 * @since 2023-01-31 11:25:39
 */
@RestController
@RequestMapping("account")
public class AccountController {
    /**
     * 服务对象
     */
    @Resource
    private AccountService accountService;

    @Resource
    private RedisService redisService;


    /**
     * 注册
     * @param account
     * @return
     */
    @PostMapping("/register")
    public CommonResult<Integer> register( Account account){
        return CommonResult.success(accountService.register(account));
    }

    /**
     * 登录
     * @param accPhone
     * @return
     */
    @RequestMapping("/login")
    public CommonResult<Account> login(String accPhone,String captcha){
        Object captcha1=redisService.get(accPhone);
        if (captcha!=null||captcha!=""){
        if (accountService.login(accPhone)!=null&&captcha.equals(captcha1)){
            redisService.del(accPhone);
            return CommonResult.success(accountService.login(accPhone));
        }else{
           return CommonResult.failed();
        }
        }
        return CommonResult.failed("验证码为空");
    }

}

